from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime


class BaseSchema(BaseModel):
    class Config:
        allow_population_by_field_name = True
        alias_generator = lambda x: ''.join(word.capitalize() if i else word for i, word in enumerate(x.split('_')))


class SysRoleBase(BaseSchema):

    role_name: Optional[str] = Field("", alias="roleName")

    role_key: Optional[str] = Field("", alias="roleKey")

    role_sort: Optional[int] = Field("", alias="roleSort")

    data_scope: Optional[str] = Field(None, alias="dataScope")

    menu_check_strictly: Optional[int] = Field(None, alias="menuCheckStrictly")

    dept_check_strictly: Optional[int] = Field(None, alias="deptCheckStrictly")

    status: Optional[str] = Field("", alias="status")

    use_flag: Optional[str] = Field(None, alias="useFlag")

    create_by: Optional[str] = Field(None, alias="createBy")

    create_time: Optional[datetime] = Field(None, alias="createTime")

    update_by: Optional[str] = Field(None, alias="updateBy")

    update_time: Optional[datetime] = Field(None, alias="updateTime")

    remark: Optional[str] = Field(None, alias="remark")


class SysRoleCreate(SysRoleBase):
    pass


class SysRoleUpdate(SysRoleBase):
    menu_ids: List[int] = Field(..., alias="menuIds")
    pass


class SysRoleDelete(BaseModel):
    ids: List[int] = Field(..., description="角色信息表ID列表")


class PageParams(BaseSchema):
    page_num: int = Field(1, ge=1, alias="pageNum", description="页码")
    page_size: int = Field(10, ge=1, le=100, alias="pageSize", description="每页数量")

    role_name: Optional[str] = Field(None, alias="roleName")

    role_key: Optional[str] = Field(None, alias="roleKey")

    data_scope: Optional[str] = Field(None, alias="dataScope")

    status: Optional[str] = Field(None, alias="status")

    use_flag: Optional[str] = Field(None, alias="useFlag")

    create_by: Optional[str] = Field(None, alias="createBy")

    update_by: Optional[str] = Field(None, alias="updateBy")

    remark: Optional[str] = Field(None, alias="remark")


class SysRoleResponse(SysRoleBase):
    role_id: int = Field(..., alias="roleId")


class RoleChange(BaseModel):
    role_id: int = Field(..., alias="roleId")
    use_flag: Optional[str] = Field("0", alias="useFlag")


class RoleData(SysRoleBase):
    role_id: int = Field(..., alias="roleId")
    dept_ids: List[int] = Field(..., alias="deptIds")


class RoleAuth(BaseSchema):
    role_id: int = Field(None, alias="roleId")
    user_id: int = Field(None, alias="userId")


class RoleAuths(BaseSchema):
    role_id: int = Field(None, alias="roleId")
    user_ids: str = Field(None, alias="userIds")
